#!/bin/bash
# 下载网址 https://nodejs.org/dist
uploadDir='/opt/software'

cd $uploadDir

echo "当前工作目录为$uploadDir"
if [ -e "node-v14.17.5-linux-x64.tar.gz" ]; then
    echo "node-v14.17.5-linux-x64.tar.gz 已存在,无需重复下载"
  else
    wget https://nodejs.org/dist/v14.17.5/node-v14.17.5-linux-x64.tar.gz
fi

if [ -d "node-v14.17.5-linux-x64" ]; then
    echo "node-v14.17.5-linux-x64 已存在,无需重复解压"
    mv node-v14.17.5-linux-x64 node
  else
    tar -xzvf node-v14.17.5-linux-x64.tar.gz
    mv node-v14.17.5-linux-x64 node

fi

# 配置环境变量
content=`cat ~/.bash_profile | grep -i node`
if [ -n "$content" ]; then
        echo "node is set and not empty,无需重复安装node"
    else
        echo "开始配置环境变量"
        echo "export PATH=$PATH:$uploadDir/node/bin" >> ~/.bash_profile
fi
source ~/.bash_profile
echo "nodejs 安装成功"
echo "以下是版本信息"
node -v
npm -v
# 1、查看镜像源
npm get registry
# 2、设置淘宝镜像
npm config set registry http://registry.npm.taobao.org/